using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Keep.Const;
using Keep.Model;
using Keep.Service;
using Microsoft.AspNetCore.Mvc;
using Serilog;

namespace Keep.Controllers;

[ApiController]
[Route("api/[controller]/[action]")]
public class LinkTypeController : ControllerBase
{

    private readonly ILinkTypeService linkTypeService;

    public LinkTypeController(ILinkTypeService linkTypeService)
    {
        this.linkTypeService = linkTypeService;
    }

    [HttpPost(Name = "GetLinkType")]
    public async Task<ActionResult<ResultData>> GetLinkType()
    {
        Log.Warning("IN");
        List<LinkType> sys = await Task.Run(() => linkTypeService.SelLinkType());
        Log.Warning("OUT => " + sys.ToString() + "  数量:" + sys.Count);
        return Ok(new ResultData(Static.Enable, sys));
    }

    [HttpPost(Name = "AddLinkTypeClick")]
    public async Task<ActionResult<ResultData>> AddLinkTypeClick(LinkType linkType)
    {
        Log.Warning("IN");
        await Task.Run(() => linkTypeService.AddLinkTypeClick((int)linkType.id));
        Log.Warning("OUT => ");
        return Ok(new ResultData(Static.Enable, true));
    }

    [HttpPost(Name = "AddLinkType")]
    public async Task<ActionResult<ResultData>> AddLinkType(LinkType linkType)
    {
        Log.Warning("IN");
        bool sys = await Task.Run(() => linkTypeService.AddLinkType(linkType));
        Log.Warning("OUT => " + sys);
        return Ok(new ResultData(Static.Enable, sys));
    }

    [HttpPost(Name = "EditLinkType")]
    public async Task<ActionResult<ResultData>> EditLinkType(LinkType linkType)
    {
        Log.Warning("IN");
        bool sys = await Task.Run(() => linkTypeService.EditLinkType(linkType));
        Log.Warning("OUT => " + sys);
        return Ok(new ResultData(Static.Enable, sys));
    }

    [HttpPost(Name = "DelLinkType")]
    public async Task<ActionResult<ResultData>> DelLinkType(LinkType linkType)
    {
        Log.Warning("IN");
        bool sys = await Task.Run(() => linkTypeService.DelLinkType((int)linkType.id));
        Log.Warning("OUT => " + sys);
        return Ok(new ResultData(Static.Enable, sys));
    }

}
